<?php
define('IN_QY',true);
require("include/common.inc.php");

// 海淘首页商品列表
//首页api
$one=$_POST['one'];

if($one!=""){
	
$reslut = "select count(*) as a FROM tbl_mother_article WHERE status=0 and cat_id=any(SELECT id FROM tbl_mother_catgroy WHERE pid='".$one."') ";




	
}	

if($one==""){
	
$reslut = "select count(*) as a from tbl_mother_article where status=0 ";
	
}

$query_reslut = mysql_query($reslut);
$row_reslut=mysql_fetch_array($query_reslut);
$count=$row_reslut['a'];
//页面数量
$page_size=5;
//总页数
$page_count = ceil($count/$page_size);

//第几页
$page=$_POST['page'];
if($page==''){
  $page=1;
}
$last=$page-1;//上一页
$next=$page+1;//下一页

if($page>$page_count){

    $arr = 0;
    echo $arr;
    exit;

}

//页面起始条数
$offset=$page_size*($page-1);
if($one!=""){
	
	if($_POST['two']!=""){
	$sql = "select t1.*, t1.id as cc ,t2.id,t2.pid from tbl_mother_article t1 inner join tbl_mother_catgroy t2 on t1.cat_id=t2.id  where t1.status=0  and t2.pid='".$one."' and t1.cat_id ='".$_POST['two']."' order by t1.id desc  limit $offset,$page_size";	
	}else {
		
//$sql = "select t1.*,t1.id as cc ,t2.id,t2.pid from tbl_mother_article t1 inner join tbl_mother_catgroy t2 on t1.cat_id=t2.id  where t1.status=0  and t2.pid='".$one."'    limit $offset,$page_size";		


$sql ="SELECT * FROM tbl_mother_article WHERE status=0 and cat_id=any(SELECT id FROM tbl_mother_catgroy WHERE pid='".$one."') order by id desc  limit $offset,$page_size";
// SELECT * FROM `tbl_mother_article` WHERE `cat_id`=any(SELECT id FROM tbl_mother_catgroy WHERE pid=17)		
	}
	
	


}
if($one==""){
$sql = "select * from tbl_mother_article  where status=0   order by id desc  limit $offset,$page_size";
}

$query = mysql_query($sql);

class Stu{  
//app首页商品表，字段解释
    public $id;  
    public $img; 
    public $title;  
    public $zan;
    public $scang;	

    public $tximg;
    public $txname;	
    public $is_business;	       
} 
while($row=mysql_fetch_object($query)){   

   	$type=$row->type; 
if($type==1){
   	$imgg=$row->show_pic; 
   	$img=explode(',',$imgg);		
	$rowg=$img['0'];	
}else {
   	$imgg=$row->pic_arr; 
    $sy=json_decode($imgg, true);

	
	
	$rowg=$sy[0]['pic_url'];		
}



	$fdd=$row->uid; 
	$idd=$row->id;
	
	$is_businesss=$row->is_business;	
	if($is_businesss==0){
		$is_businesse='ge';
	}else {
		$is_businesse='shang';
	}
	
	$sqljnamee = "SELECT DISTINCT * from tbl_user  where id='".$fdd."' ";
    $queryjnamee=mysql_query($sqljnamee);
    $rowjnamee=mysql_fetch_array($queryjnamee);	
	
						$sqluyo = "SELECT count(*) as b from tbl_mother_article_love  where article_id='".$idd."'  ";
                        $queryuyo=mysql_query($sqluyo);
                        $rowuyo=mysql_fetch_array($queryuyo);
						
					    $sqlcollect = "SELECT count(*) as c from tbl_mother_article_collect  where article_id='".$idd."' ";
                        $querycollect=mysql_query($sqlcollect);
                        $rowcollect=mysql_fetch_array($querycollect);
						
						
	
    $s=new Stu();
    $s->id=$row->id;  
    $s->title=$row->title;  
 
  	
	$s->img=$rowg; 
    $s->tximg=$rowjnamee['username'];   
    $s->txname=$rowjnamee['shuyu']; 
	$s->zan=$rowuyo['b']; 
	$s->scang=$rowcollect['c']; 	
	$s->is_business=$is_businesse;  	
	$arr[]=$s;
} 
echo json_encode(array('data'=>$arr)); 

//
